Ext.namespace("Ext.Lanmon");
Ext.Lanmon = {
    ready:function(){
        var centerPanel = Ext.create("Ext.TabPanel",{
            id:'tabpanel',
            region:'center',
            xtype:'tabpanel',
            activeTab:0,
            minTabWidth:120,
            items:[{
                title:'系统首页'
            }],
            bodyStyle:"border-bottom:0px"
        });
        var westPanel = Ext.create("Ext.panel.Panel",{
            id:'westPanel',
            layout:'accordion',
            region:'west',
            title:'系统导航',
            width:220,
            collapsible:true,
            split:true,
            minWidth:200,
            maxWidth:400,
            bodyStyle:"border-bottom:0px"
        });
        Ext.create("Ext.container.Viewport",{
            renderTo:Ext.getBody(),
            layout:'border',
            items:[{
                //title:'蓝梦软件框架设计',
                region:'north',
                height:60,
                contentEl:'north'
            },centerPanel,westPanel,{
                region:'south',
                height:20,
                bodyStyle:'background-color:#DFE8F6',
                contentEl:'south'
            }]
        });
        //注册树模型，用于添加自定义属性
        Ext.define("treemodel",{
            extend:'Ext.data.Model',
            idProperty:'id',
            fields:[
                {name:'id'},
                {name:'text'},
                {name:'url'},
                {name:'leaf'},
                {name:'expanded'},
                {name:'children'}
            ]
        });
        var store = Ext.create('Ext.data.TreeStore', {
            model:'treemodel',
            root: {
                expanded: true,
                children: [
                    {id:'n1',text:"detention",leaf:true,url:contextPath+'/auth/userMaintain',checked:false},
                    {text:"homework",expanded:true,children:[{text:"book report",leaf:true},{text:"algebra",leaf:true}]},
                    {text:"buy lottery tickets",leaf:true}
                ]
            }
        });

        var menuPanel = Ext.create("Ext.tree.Panel",{
            title:'系统管理',
            store:store,
            rootVisible:false,
           /* columns: [{
                xtype: 'treecolumn',
                text: 'Name',
                dataIndex: 'text',
                width: 150,
                sortable: true
            }, {
                text: 'Description',
                dataIndex: 'url',
                flex: 1,
                sortable: true
            }],*/
            listeners:{  
                itemclick:function(view,record,item,index,e,eOpts){
                	var leaf = record.get("leaf");
                	if(!leaf)
                	   return false;
                	var nodeId = record.get("id");
                	var panelId = "panel_" + nodeId;
                	var panel = Ext.getCmp(panelId);
                	if(panel == null){
                        panel = Ext.create("Ext.panel.Panel",{
                    	   id:panelId,
                    	   title:record.get("text"),
                           closable:true,
                           html:'<iframe src='+record.get("url")+' width="100%" height="100%" frameborder="0" scrolling="auto"></iframe>'
                    	});
                    	centerPanel.add(panel);
                	} 
                	centerPanel.setActiveTab(panel);
                }  
            }  
        });
        westPanel.add(menuPanel);
        Ext.Msg.showParentNotify({title:'提示', msg:'登录成功！'}); 
        
        var closeButton = Ext.create("Ext.button.Button",{
        	text:'退出',
            iconCls : 'banner-sys-config-logout',
            iconAlign : 'left',
            scale   : 'medium',
            width : 65,
            height:30,
            tooltip : '<span style="font-size:12px">'+'注销系统'+'</span>',
            pressed : true,
            renderTo : 'logoutBtn',
            handler : function() {
                Ext.Msg.confirm('确认退出','是否确认退出系统？',function(val){
                    if(val == 'yes'){
                        window.location.href = contextPath + '/auth/logout';
                    }
                });
            }
        });
    }
};
Ext.apply(Ext.Lanmon);
Ext.onReady(Ext.Lanmon.ready,Ext.Lanmon);